package main

import (
	"fmt"

	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

var devImg = []string{
	"imgs/2d918393-98c6-4ff9-96d4-7c696a93b7cc.png",
	"imgs/f3ce2f2d-b3ef-4788-953e-cfb13974deb1.jpg",
	"imgs/b96c54da-bda8-4fa6-9de9-c35182896b29.png",
	"imgs/592fabc0-69ef-4554-b9c3-e9f3f1947790.jpeg",
	"imgs/b31689b1-2954-4a01-a6bf-6a77f1442f03.jpeg",
	"imgs/fc0015ba-11c3-4fd9-baa6-0a40dde5318c.jpeg",
	"imgs/89279d5d-2dc2-45c8-9cce-a668e72ed111.jpg",
	"imgs/25fe5138-79d0-475d-97ab-44264cf4b4fb.jpg",
	// "imgs/bec01151-0a20-469f-9ff2-7703a73e024a.jpg",
	"imgs/0b6bd1a3-8cca-4c95-b765-55c2474afbbe.png",
	"imgs/140bfd55-c090-451f-b6f5-c75ec595fff3.png",
	"imgs/d4b76f57-d2c7-4911-8872-700e45937367.png",
	"imgs/bbc5c9af-3f08-4109-b1f2-e9ae52567ec3.png",
}

//   bucketName: xxkj-unicenter-dev
//   endpoint: oss-cn-beijing.aliyuncs.com
//   accessKeyId: LTAI5tCkxLDnbWB1DzjRqUkB
//   accessKeySecret: pxqAds67PfYdE8oDPet8SvCbVVSLR3
//   domain: https://xxkj-unicenter-dev.oss-cn-beijing.aliyuncs.com
//   ossDomain: http://xxkj-unicenter-dev.oss-cn-beijing.aliyuncs.com

type ossConf struct {
	BucketName      string
	DestBucketName  string
	Endpoint        string
	AccessKeyId     string
	AccessKeySecret string
}

func main() {
	// https://xxkj-unicenter-home.oss-cn-beijing.aliyuncs.com
	xxx := ossConf{
		BucketName:      "xxkj-one",
		DestBucketName:  "xxkj-unicenter-product",
		Endpoint:        "oss-cn-beijing.aliyuncs.com",
		AccessKeyId:     "LTAI5tCkxLDnbWB1DzjRqUkB",
		AccessKeySecret: "pxqAds67PfYdE8oDPet8SvCbVVSLR3",
	}
	err := xxx.move()
	if err != nil {
		fmt.Println(err.Error())
	} else {
		fmt.Println("处理完毕...")
	}

}

// Upload oss 文件上传
func (toss ossConf) move() error {
	client, err := oss.New(toss.Endpoint, toss.AccessKeyId, toss.AccessKeySecret)
	if err != nil {
		return err
	}

	// 填写存储空间名称，例如examplebucket。
	bucket, err := client.Bucket(toss.BucketName)
	if err != nil {
		return err
	}
	for _, img := range devImg {
		fmt.Println(img)
		rest, err := bucket.CopyObjectTo(toss.DestBucketName, img, img)
		if err != nil {
			return err
		}
		fmt.Println(rest.XMLName)
	}
	return nil
}

// -- 替换用户头像
// SELECT * FROM users WHERE avatar like 'https://xxkj-unicenter-test.oss-cn-beijing.aliyuncs.com/""imgs/%';",",
// update users set avatar = replace(avatar, '""imgs', 'https://xxkj-unicenter-test.oss-cn-beijing.aliyuncs.com/imgs');",",

// -- 替换企业 logo
// SELECT * FROM tenants WHERE logo like '""imgs/%';",",
// update tenants set logo = replace(logo, '""imgs', 'https://xxkj-unicenter-test.oss-cn-beijing.aliyuncs.com/imgs');",",

// -- 替换 apps
// SELECT * FROM apps WHERE icon like '""imgs/%';",",
// update apps set icon = replace(icon, '""imgs', 'https://xxkj-unicenter-test.oss-cn-beijing.aliyuncs.com/imgs');",",
